package com.roc.steelend.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.mapper.BigTypeMapper;
import com.roc.steelend.mapper.SmallTypeMapper;
import com.roc.steelend.pojo.BigType;
import com.roc.steelend.pojo.SmallType;
import com.roc.steelend.service.BigTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.jws.Oneway;
import javax.management.Query;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class BigTypeServiceImpl implements BigTypeService {

    @Autowired
    private BigTypeMapper bigTypeMapper;
    @Autowired
    private SmallTypeMapper smallTypeMapper;

    @Override
    public List<BigType> selectBigTypeShow(Integer smallTypeId) {
        QueryWrapper<BigType> wrapper = new QueryWrapper<>();
        if (smallTypeId!=null){
            QueryWrapper<SmallType> wrapper1 = new QueryWrapper<>();
            wrapper1.eq("small_type_id",smallTypeId)
                    .last("LIMIT 1");
            List<SmallType> smallTypes = smallTypeMapper.selectList(wrapper1);
            Integer bigTypeId = smallTypes.get(0).getBigTypeId();
            wrapper.eq("big_type_id",bigTypeId);
        }

        return bigTypeMapper.selectList(wrapper);
    }

    @Override
    public ReturnMsgForTable selectBigTypeShowDetail(Integer now, Integer size) {
        Page<BigType> page = new Page<>(now,size);
        bigTypeMapper.selectPage(page,null);
        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setCurrenPage(now);
        returnMsgForTable.setTotal(Integer.valueOf(String.valueOf(page.getTotal())));
        returnMsgForTable.setObjectList(page.getRecords());
        return returnMsgForTable;
    }
}
